package com.itheima.prize.commons.db.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.prize.commons.db.entity.CardUser;
import com.itheima.prize.commons.db.service.CardUserService;
import com.itheima.prize.commons.db.mapper.CardUserMapper;
import com.itheima.prize.commons.utils.PasswordUtil;
import org.springframework.stereotype.Service;

/**
 * @author shawn
 * @description 针对表【card_user(会员信息表)】的数据库操作Service实现
 * @createDate 2023-12-26 11:58:48
 */
@Service
public class CardUserServiceImpl extends ServiceImpl<CardUserMapper, CardUser>
        implements CardUserService {

    @Override
    public CardUser login(String account, String password) {
        //进行密码加密
        password = PasswordUtil.encodePassword(password);
        //构建查询条件
        QueryWrapper<CardUser> wrapper = new QueryWrapper<CardUser>().eq("uname", account).eq("passwd", password);
        //查询后得到数据并封装
        CardUser user = getOne(wrapper);
        //查询不到，用户名或密码错误
        if (user == null) {
            return null;
        }
        //前端不给看 返回null吧
        user.setPasswd(null);
        user.setIdcard(null);
        return user;


    }
}




